﻿using System.Collections.Generic;

namespace MhAdmin.SqlSugar;

/// <summary>
/// 规则扩展
/// </summary>
public class RuleEnumerator<T> : IDisposable
{
    private List<T> List { get; set; }
    private int Position;

    public RuleEnumerator(List<T> data)
    {
        List = data;
        Position = 0;
    }

    /// <summary>
    /// 获取下一个编码
    /// </summary>
    public T Current => Next();

    /// <summary>
    /// 是否有下一个编码
    /// </summary>
    public bool HasNext => Position < List.Count;

    /// <summary>
    /// 获取下一个编码
    /// </summary>
    /// <returns></returns>
    public T Next()
    {
        Position++;
        if (Position > List.Count) return default;
        else return List[Position - 1];
    }

    /// <summary>
    /// 重置指针到开头
    /// </summary>
    public void ReSet()
    {
        Position = 0;
    }

    public void Dispose() => GC.SuppressFinalize(this);
}
